home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12528 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: routine for yesterday's date
  5. Date: Mon, 01 Apr 1996 04:05:52 GMT
  6. Organization: Netcom
  7. Message-ID: <315f54bc.483131085@nntp.ix.netcom.com>
  8. References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com> <Dp3B56.FKI@alisa.org>
  9. NNTP-Posting-Host: ix-dc10-09.ix.netcom.com
  10. X-NETCOM-Date: Sun Mar 31  8:05:40 PM PST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. wjjr@alisa.org (John J. Rushford) wrote:
  14.  
  15. > Mark Brader (msb@sq.com) wrote:
  16. > : Bruce Coghill (75323.455@compuserve.com) writes at 2:48 PM, March 29, 1996:
  17. > :  
  18. > : > In my C manual the time.h and time functions are described
  19. > : > and how I can pull off each element in the structure (like year,
  20. > : > month, day, day-of-the-year), but it isn't clear to me how to subtract
  21. > : > a day.
  22. > : This is question 13.14 on the FAQ list, but I'd like to expand a bit
  23. > : on what it says there.
  24. > : Bruce, you have gotten as far as calling time() and localtime().  The
  25. > : next thing is to use the normalizing feature of mktime().  Suppose that
  26. > : you have a variable of type struct tm called x, and you've just put the
  27. > : current time into it using localtime().  Now you basically just want to
  28. > : do something like this:
  29. > :     x.tm_day--;          /* back 1 day */
  30. > :     (void) mktime (&x);    /* normalize */
  31. > [stuff deleted]
  32. > Why bother with mktime() when it is so much easier to use the following and
  33. > you don't have to bother with errors gotten from x.tm_day--;
  34. >     long ticks
  35. >     struct tm * dt;
  36. >     time(&ticks);
  37. >     /* 86400 seconds in a day */
  38. >     ticks -= 86400
  39. >     dt = localtime (&ticks);
  40.  
  41. Let me make a wild guess as to why Mark suggested the method he did
  42. rather than your much simpler method.  Perhaps it was because your
  43. code is illegal in standard C.  
  44.  
  45. time() taks a time_t*, not a long* as an argument.  time_t may be any
  46. arithmetic type.  Furthermore, nothing in the standard suggests that
  47. subtracting 86400 from a time_t does anything useful, let alone
  48. decrement the time by one day.
  49.  
  50.  
  51. Michael M Rubenstein
  52.